/*
 * @Author: 张小平
 * @Date:   2025-05-01 
 * @Email:  qqshuqian@163.com 
 * @Copyright © 2024 aseyun. All rights reserved.
 */
import {isMobile, validateEmail} from "./validate";

const validateMobileRule = (rule, value, callback) => {
    if (!isMobile(value)) {
        callback(new Error("请输入正确的手机号格式"));
    } else {
        callback();
    }
};
 const validateIdNoRule  = (rule, value, callback) => {
    let id18 = /^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/;
    let id15 = /^[1-9]\d{5}\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{2}$/;
    if (!id18.test(value) && !id15.test(value)) {
        callback(new Error("请输入正确的身份证号格式"));
    } else {
        callback();
    }
};

 const validateEmailRule  = (rule, value, callback) => {
     if (!validateEmail(value)) {
         callback(new Error("请输入正确的邮箱格式"));
     } else {
         callback();
     }
 };


 export const validateRules = {
    "mobile": [{ required: true, trigger: "blur", validator: validateMobileRule  }],
    "idcard": [{ required: true, trigger: "blur", validator: validateIdNoRule  }],
    "email": [{ required: true, trigger: "blur", validator: validateEmailRule  }]
};




// export function getValidateRule(rule) {
//     return validateRules[rule];
// }
